<?php
/**
 * 好商城控件管理
 *
 * @好商城提供技术支持 授权请购买shopnc授权
 * @license    http://www.33hao.com
 * @link       交流群号：138182377
 */
defined('In33hao') or exit('Access Invalid!');

class haoControl extends SystemControl
{
    private $links = array(
        array('url' => 'act=hao&op=base', 'lang' => 'hao_set'),
        array('url' => 'act=hao&op=banner', 'lang' => 'top_set'),
        array('url' => 'act=hao&op=lc', 'lang' => 'lc_set'),
        array('url' => 'act=hao&op=sms', 'lang' => 'sms_set'),
        //临时注释
//		array('url'=>'act=hao&op=rc','lang'=>'rc_set'),
        array('url' => 'act=hao&op=webchat', 'lang' => 'webchat_set'),
        array('url' => 'act=hao&op=diymenu', 'lang' => 'diymenu'),

    );

    public function __construct()
    {
        parent::__construct();
        Language::read('hao,setting');
    }

    public function indexOp()
    {
        $this->baseOp();
    }

    /**
     * 基本信息
     */
    public function baseOp()
    {
        $model_setting = Model('setting');
        if (chksubmit()) {
            $list_setting = $model_setting->getListSetting();
            $update_array = array();
            $update_array['hao_mail'] = $_POST['hao_mail'];
            $update_array['hao_phone'] = $_POST['hao_phone'];
            $update_array['hao_time'] = $_POST['hao_time'];
            $update_array['points_invite'] = intval($_POST['points_invite']) ? $_POST['points_invite'] : 0;
            $update_array['points_rebate'] = intval($_POST['points_rebate']) ? $_POST['points_rebate'] : 0;
            $result = $model_setting->updateSetting($update_array);
            if ($result === true) {
                $this->log(L('nc_edit,hao_set'), 1);
                showMessage(L('nc_common_save_succ'));
            } else {
                $this->log(L('nc_edit,hao_set'), 0);
                showMessage(L('nc_common_save_fail'));
            }
        }
        $list_setting = $model_setting->getListSetting();

        Tpl::output('list_setting', $list_setting);
        //输出子菜单
        Tpl::output('top_link', $this->sublink($this->links, 'base'));
        Tpl::setDirquna('system');
        Tpl::showpage('hao.base');
    }

    /**
     * 顶部广告信息
     */
    public function bannerOp()
    {
        $model_setting = Model('setting');
        if (chksubmit()) {
            if (!empty($_FILES['hao_top_banner_pic']['name'])) {
                $upload = new UploadFile();
                $upload->set('default_dir', ATTACH_COMMON);
                $result = $upload->upfile('hao_top_banner_pic');
                if ($result) {
                    $_POST['hao_top_banner_pic'] = $upload->file_name;
                } else {
                    showMessage($upload->error, '', '', 'error');
                }
            }
            $list_setting = $model_setting->getListSetting();
            $update_array = array();
            $update_array['hao_top_banner_name'] = $_POST['top_banner_name'];
            $update_array['hao_top_banner_url'] = $_POST['top_banner_url'];
            $update_array['hao_top_banner_color'] = $_POST['top_banner_color'];
            $update_array['hao_top_banner_status'] = $_POST['top_banner_status'];
            if (!empty($_POST['hao_top_banner_pic'])) {
                $update_array['hao_top_banner_pic'] = $_POST['hao_top_banner_pic'];
            }
            $result = $model_setting->updateSetting($update_array);
            if ($result === true) {
                //判断有没有之前的图片，如果有则删除
                if (!empty($list_setting['hao_top_banner_pic']) && !empty($_POST['hao_top_banner_pic'])) {
                    @unlink(BASE_UPLOAD_PATH . DS . ATTACH_COMMON . DS . $list_setting['hao_top_banner_pic']);
                }
                $this->log(L('nc_edit,top_set'), 1);
                showMessage(L('nc_common_save_succ'));
            } else {
                $this->log(L('nc_edit,top_set'), 0);
                showMessage(L('nc_common_save_fail'));
            }
        }

        $list_setting = $model_setting->getListSetting();

        Tpl::output('list_setting', $list_setting);

        //输出子菜单
        Tpl::output('top_link', $this->sublink($this->links, 'banner'));

        Tpl::setDirquna('system');
        Tpl::showpage('hao.banner');
    }

    /**
     * 楼层快速直达列表
     */
    public function lcOp()
    {
        $model_setting = Model('setting');
        $lc_info = $model_setting->getRowSetting('hao_lc');
        if ($lc_info !== false) {
            $lc_list = @unserialize($lc_info['value']);
        }
        if (!$lc_list && !is_array($lc_list)) {
            $lc_list = array();
        }
        Tpl::output('lc_list', $lc_list);
        Tpl::output('top_link', $this->sublink($this->links, 'lc'));
        Tpl::setDirquna('system');
        Tpl::showpage('hao.lc');
    }

    /**
     * 楼层快速直达添加
     */
    public function lc_addOp()
    {
        $model_setting = Model('setting');
        $lc_info = $model_setting->getRowSetting('hao_lc');
        if ($lc_info !== false) {
            $lc_list = @unserialize($lc_info['value']);
        }
        if (!$lc_list && !is_array($lc_list)) {
            $lc_list = array();
        }
        if (chksubmit()) {
            if (count($lc_list) >= 8) {
                showMessage('最多可设置8个楼层', 'index.php?act=hao&op=lc');
            }
            if ($_POST['lc_name'] != '' && $_POST['lc_value'] != '') {
                $data = array('name' => stripslashes($_POST['lc_name']), 'value' => stripslashes($_POST['lc_value']));
                array_unshift($lc_list, $data);
            }
            $result = $model_setting->updateSetting(array('hao_lc' => serialize($lc_list)));
            if ($result) {
                showMessage('保存成功', 'index.php?act=hao&op=lc');
            } else {
                showMessage('保存失败');
            }
        }
        Tpl::setDirquna('system');

        Tpl::showpage('hao.lc_add');
    }

    /**
     * 删除
     */
    public function lc_delOp()
    {
        $model_setting = Model('setting');
        $lc_info = $model_setting->getRowSetting('hao_lc');
        if ($lc_info !== false) {
            $lc_list = @unserialize($lc_info['value']);
        }
        if (!empty($lc_list) && is_array($lc_list) && intval($_GET['id']) >= 0) {
            unset($lc_list[intval($_GET['id'])]);
        }
        if (!is_array($lc_list)) {
            $lc_list = array();
        }
        $result = $model_setting->updateSetting(array('hao_lc' => serialize(array_values($lc_list))));
        if ($result) {
            showMessage('删除成功');
        }
        showMessage('删除失败');
    }

    /**
     * 编辑
     */
    public function lc_editOp()
    {
        $model_setting = Model('setting');
        $lc_info = $model_setting->getRowSetting('hao_lc');
        if ($lc_info !== false) {
            $lc_list = @unserialize($lc_info['value']);
        }
        if (!is_array($lc_list)) {
            $lc_list = array();
        }
        if (!chksubmit()) {
            if (!empty($lc_list) && is_array($lc_list) && intval($_GET['id']) >= 0) {
                $current_info = $lc_list[intval($_GET['id'])];
            }
            Tpl::output('current_info', is_array($current_info) ? $current_info : array());
            Tpl::setDirquna('system');
            Tpl::showpage('hao.lc_add');
        } else {
            if ($_POST['lc_name'] != '' && $_POST['lc_value'] != '' && $_POST['id'] != '' && intval($_POST['id']) >= 0) {
                $lc_list[intval($_POST['id'])] = array('name' => stripslashes($_POST['lc_name']), 'value' => stripslashes($_POST['lc_value']));
            }
            $result = $model_setting->updateSetting(array('hao_lc' => serialize($lc_list)));
            if ($result) {
                showMessage('编辑成功', 'index.php?act=hao&op=lc');
            }
            showMessage('编辑失败');
        }


    }

    /**
     * 首页热门关键词链接
     */
    public function rcOp()
    {
        $model_setting = Model('setting');
        $rc_info = $model_setting->getRowSetting('hao_rc');
        if ($rc_info !== false) {
            $rc_list = @unserialize($rc_info['value']);
        }
        if (!$rc_list && !is_array($rc_list)) {
            $rc_list = array();
        }
        Tpl::output('rc_list', $rc_list);
        Tpl::output('top_link', $this->sublink($this->links, 'rc'));
        Tpl::setDirquna('system');
        Tpl::showpage('hao.rc');
    }

    /**
     * 楼层快速直达添加
     */
    public function rc_addOp()
    {
        $model_setting = Model('setting');
        $rc_info = $model_setting->getRowSetting('hao_rc');
        if ($rc_info !== false) {
            $rc_list = @unserialize($rc_info['value']);
        }
        if (!$rc_list && !is_array($rc_list)) {
            $rc_list = array();
        }
        if (chksubmit()) {
            if (count($rc_list) >= 8) {
                showMessage('最多可设置8个楼层', 'index.php?act=hao&op=rc');
            }
            if ($_POST['rc_name'] != '' && $_POST['rc_value'] != '' && $_POST['rc_blod'] != '') {
                $data = array('name' => stripslashes($_POST['rc_name']), 'value' => stripslashes($_POST['rc_value']), 'is_blod' => stripslashes($_POST['rc_blod']));
                array_unshift($rc_list, $data);
            }
            $result = $model_setting->updateSetting(array('hao_rc' => serialize($rc_list)));
            if ($result) {
                showMessage('保存成功', 'index.php?act=hao&op=rc');
            } else {
                showMessage('保存失败');
            }
        }
        Tpl::setDirquna('system');

        Tpl::showpage('hao.rc_add');
    }

    /**
     * 删除
     */
    public function rc_delOp()
    {
        $model_setting = Model('setting');
        $rc_info = $model_setting->getRowSetting('hao_rc');
        if ($rc_info !== false) {
            $rc_list = @unserialize($rc_info['value']);
        }
        if (!empty($rc_list) && is_array($rc_list) && intval($_GET['id']) >= 0) {
            unset($rc_list[intval($_GET['id'])]);
        }
        if (!is_array($rc_list)) {
            $rc_list = array();
        }
        $result = $model_setting->updateSetting(array('hao_rc' => serialize(array_values($rc_list))));
        if ($result) {
            showMessage('删除成功');
        }
        showMessage('删除失败');
    }

    /**
     * 编辑
     */
    public function rc_editOp()
    {
        $model_setting = Model('setting');
        $rc_info = $model_setting->getRowSetting('hao_rc');
        if ($rc_info !== false) {
            $rc_list = @unserialize($rc_info['value']);
        }
        if (!is_array($rc_list)) {
            $rc_list = array();
        }
        if (!chksubmit()) {
            if (!empty($rc_list) && is_array($rc_list) && intval($_GET['id']) >= 0) {
                $current_info = $rc_list[intval($_GET['id'])];
            }
            Tpl::output('current_info', is_array($current_info) ? $current_info : array());
            Tpl::setDirquna('system');
            Tpl::showpage('hao.rc_add');
        } else {
            if ($_POST['rc_name'] != '' && $_POST['rc_value'] != '' && $_POST['rc_blod'] != '' && $_POST['id'] != '' && intval($_POST['id']) >= 0) {
                $rc_list[intval($_POST['id'])] = array('name' => stripslashes($_POST['rc_name']), 'value' => stripslashes($_POST['rc_value']), 'is_blod' => stripslashes($_POST['rc_blod']));
            }
            $result = $model_setting->updateSetting(array('hao_rc' => serialize($rc_list)));
            if ($result) {
                showMessage('编辑成功', 'index.php?act=hao&op=rc');
            }
            showMessage('编辑失败');
        }


    }

    /**
     * 短信平台设置
     */
    public function smsOp()
    {
        $model_setting = Model('setting');
        if (chksubmit()) {
            $update_array = array();
            $update_array['hao_sms_type'] = $_POST['hao_sms_type'];
            $update_array['hao_sms_tgs'] = $_POST['hao_sms_tgs'];
            $update_array['hao_sms_zh'] = $_POST['hao_sms_zh'];
            $update_array['hao_sms_pw'] = $_POST['hao_sms_pw'];
            $update_array['hao_sms_key'] = $_POST['hao_sms_key'];
            $update_array['hao_sms_signature'] = $_POST['hao_sms_signature'];
            $update_array['hao_sms_bz'] = $_POST['hao_sms_bz'];
            $result = $model_setting->updateSetting($update_array);
            if ($result === true) {
                $this->log(L('nc_edit,sms_set'), 1);
                showMessage(L('nc_common_save_succ'));
            } else {
                $this->log(L('nc_edit,sms_set'), 0);
                showMessage(L('nc_common_save_fail'));
            }
        }
        $list_setting = $model_setting->getListSetting();
        Tpl::output('list_setting', $list_setting);

        Tpl::output('top_link', $this->sublink($this->links, 'sms'));
        Tpl::setDirquna('system');
        Tpl::showpage('hao.sms');
    }

    /**
     * 默认微信公众号设置
     */
    public function webchatOp()
    {
        $model_setting = Model('setting');
        if (chksubmit()) {
            $update_array = array();
            $update_array['hao_webchat_appid'] = $_POST['hao_webchat_appid'];
            $update_array['hao_webchat_appsecret'] = $_POST['hao_webchat_appsecret'];
            $update_array['hao_webchat_token'] = $_POST['hao_webchat_token'];
            $result = $model_setting->updateSetting($update_array);
            if ($result === true) {
                $this->log(L('nc_edit,sms_set'), 1);
                showMessage(L('nc_common_save_succ'));
            } else {
                $this->log(L('nc_edit,sms_set'), 0);
                showMessage(L('nc_common_save_fail'));
            }
        }
        $list_setting = $model_setting->getListSetting();
        Tpl::output('list_setting', $list_setting);
        Tpl::output('top_link', $this->sublink($this->links, 'webchat'));
        Tpl::setDirquna('system');
        Tpl::showpage('hao.webchat');
    }


    /**
     * 自定义菜单菜单
     *
     * @param
     * @return
     */
    public function diymenuOp()
    {
        $model = Model('diymenu');
        $wx_class = $model->getTreeClassList();
        if (is_array($wx_class) and count($wx_class) > 0) {
            foreach ($wx_class as $key => $val) {
                if ($val['deep'] > 1) {
                    $wx_class[$key]['title'] = str_repeat('&nbsp;', $val['deep'] * 3) . '┗ ' . $val['title'];
                }
            }
        }
        Tpl::output('wx_class', $wx_class);
        Tpl::output('top_link', $this->sublink($this->links, 'diymenu'));
        Tpl::setDirquna('system');
        Tpl::showpage('hao.diymenu');
    }

    /**
     * 检查新增下级
     *
     * @param
     * @return
     */
    public function check_add_classOp()
    {
        $model = Model('diymenu');
        $type = $_GET['type'];
        $data['status'] = 0;
        if ($type) {
            $res = $model->checkLevelOne();
            $data['url'] = 'index.php?act=hao&op=diymenu_class_add';
        } else {
            $pid = $_GET['id'];
            $res = $model->checkLevelTwo($pid);
            $data['url'] = 'index.php?act=hao&op=diymenu_class_two&pid=' . $pid;
        }
        if ($res) {
            $data['status'] = 1;
        }
        exit(json_encode($data));
    }


    /**
     * 检查新增下级
     *
     * @param
     * @return
     */
    public function diymenu_ajaxOp()
    {
        $model = Model('diymenu');
        $pid = $_GET['id'];
        $title = $_GET['title'];
        $res = $model->getDiymenuList(['pid' => $pid, 'title' => $title]);
        if ($res) {
            echo 'false';
            exit;
        }
        echo 'true';
        exit;
    }

    /**
     * 检查新增下级
     *
     * @param
     * @return
     */
    public function diymenu_sort_ajaxOp()
    {
        $model = Model('diymenu');
        $id = $_GET['id'];
        $sort = $_GET['value'];
        $data['result'] = $model->editDiymenu(['id' => $id], ['sort' => $sort]);
        exit(json_encode($data));
    }


    /*
     * 添加顶级微信菜单
     *
     */

    public function diymenu_class_addOp()
    {
        $model = Model('diymenu');
        if ($_POST) {
            $res = $model->checkLevelOne();
            if (!$res) {
                showMessage('一级菜单只能添加3个！');
            }
            $data['title'] = $_POST['title'];
            $data['keyword'] = trim($_POST['keyword']);
            $data['url'] = trim($_POST['url']);
            $data['sort'] = intval($_POST['sort']);
            $data['is_show'] = trim($_POST['is_show']);
            if ($data['title'] == '') {
                showMessage('菜单名称不能为空');
            }
            $result = $model->addDiymenu($data);
            if ($result) {
                showMessage('添加成功');
            } else {
                showMessage('添加失败，请稍后再试');
            }
        }
        Tpl::output('module', $this->modules());
        Tpl::setDirquna('system');
        Tpl::showpage('hao.diymenu_class_add');
    }

    /*
        * 添加下级微信菜单
        *
        */

    public function diymenu_class_twoOp()
    {
        $model = Model('diymenu');
        $parent_list = $model->getDiymenuList(array('pid' => 0));
        if ($_POST) {
            $pid = trim($_POST['pid']);
            $res = $model->checkLevelTwo($pid);
            if (!$res) {
                showMessage('二级菜单只能添加5个！');
            }
            $res = $model->getDiymenuList(['title' => $_POST['title']]);
            if ($res) {
                showMessage('该菜单名称已存在！');
            }
            $data['title'] = $_POST['title'];
            $data['keyword'] = trim($_POST['keyword']);
            $data['pid'] = $pid;
            $data['url'] = trim($_POST['url']);
            $data['sort'] = intval($_POST['sort']);
            $data['is_show'] = trim($_POST['is_show']);
            if ($data['title'] == '') {
                showMessage('菜单名称不能为空');
            }
            $res = $model->addDiymenu($data);
            if ($res) {
                showMessage('添加成功', 'index.php?act=hao&op=diymenu');
            } else {
                showMessage('添加失败，请稍后再试');
            }
        }
        Tpl::setDirquna('system');
        Tpl::output('parent_list', $parent_list);
        Tpl::output('pid', $_GET['pid']);
        Tpl::output('module', $this->modules());
        Tpl::showpage('hao.diymenu_class_two');
    }

    /*
     *  功能库
     *
     *
     *
     * **/

    public function modules()
    {
//        $model = Model('article');
//        $info = $model->getArticleList(array('store_id' => $_SESSION['store_id']));
//        foreach($info as $v){
//            $infos[] = array(
//                'module' => 'Home',
//                'linkcode' => 'http://www.jiniu.cc/Wap/Index/brand/id/'.$v['article_id'].'/token/'.touid($_SESSION['store_id']),
//                'name' => $v['article_title'],
//                'sub' => 0,
//                'canselected' => 1,
//                'linkurl' => '',
//                'keyword' => $this->modules['Home'],
//                'askeyword' => 1
//            );
//        }


        $in = array(
            array(
                'title' => '商城首页',
                'url' => urlShop(),
            ),
            array(
                'title' => '购物车',
                'url' => urlShop(),
            ),
            array(
                'title' => '我的订单',
                'url' => urlShop(),
            ),
            array(
                'title' => '个人中心',
                'url' => urlShop(),
            ),
            array(
                'title' => '我的分享',
                'url' => urlShop(),
            ),
            array(
                'title' => '我的代理',
                'url' => urlShop(),
            ),
        );
//        if($infos == null){
//            return $in;
//        }else{
//            return array_merge($in, $infos);
//        }

        return $in;
    }


    /*
     * 菜单编辑
     */

    public function diymenu_editOp()
    {
        $model = Model('diymenu');
        $id = $_GET['id'];
        $res = $model->getDiymenuInfo(array('id' => $id));
        if ($_POST) {
            $id = intval($_POST['id']);
            $data['title'] = trim($_POST['title']);
            $data['keyword'] = trim($_POST['keyword']);
            $data['url'] = trim($_POST['url']);
            $data['sort'] = intval($_POST['sort']);
            $data['is_show'] = trim($_POST['is_show']);
            if ($data['title'] == '') {
                showMessage('菜单名称不能为空');
            }
            $res = $model->editDiymenu(array('id' => $id), $data);
            if ($res) {
                showMessage('修改成功');
            } else {
                showMessage('修改失败');
            }
        }
        Tpl::setDirquna('system');
        Tpl::output('module', $this->modules());
        Tpl::output('res', $res);
        Tpl::showpage('hao.diymenu_class_edit');
    }

    /*
     * 菜单删除
     */

    public function diymenu_deleteOp()
    {
        $model = Model('diymenu');
        $id = $_GET['id'];
        $data['status'] = 1;
        if (!empty($id)) {
            if (strstr($id, ',')) {
                $ids = explode(',', $id);
                foreach ($ids as $v) {
                    $result = $model->del($v);
                    if (!$result) {
                        $data['status'] = 0;
                    }
                }
            } else {
                $result = $model->del($id);
                if (!$result) {
                    $data['status'] = 0;
                }
            }
        }
        exit(json_encode($data));
    }

    /*
     * 菜单生成
     */

    public function menu_sendOp()
    {
        $model = Model('setting');
        $model_class = Model('diymenu');
        $info = $model->getListSetting();
        $appid = $info['hao_webchat_appid'];
        $secret = $info['hao_webchat_appsecret'];
        if ($_GET) {
            $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' .
                $appid . '&secret=' . $secret;
            $json = json_decode($this->curlGet($url_get));
            if (!$json) {
                showMessage('获取access_token发生错误');
            }
            $data = '{"button":[';
            $class = $model_class->getDiymenuList(array('pid' => 0, 'is_show' => 1), 'sort asc', 3);
            $kcount = $model_class->getDiymenuCount(array('pid' => 0, 'is_show' => 1), 'sort asc', 3);
            $k = 1;
            foreach ($class as $key => $vo) {
                //主菜单
                $data .= '{"name":"' . $vo['title'] . '",';
                $c = $model_class->getDiymenuList(array('pid' => $vo['id'], 'is_show' => 1), 'sort asc', 5);
                $count = $model_class->getDiymenuCount(array('pid' => $vo['id'], 'is_show' => 1), 'sort asc', 5);
                //子菜单
                $vo['url'] = str_replace(array(
                    '{siteUrl}',
                    '&amp;',
                    '&wecha_id={wechat_id}'), array(
                    $this->siteUrl,
                    '&',
                    '&diymenu=1'), $vo['url']);
                if ($c != false) {
                    $data .= '"sub_button":[';
                } else {
                    if (!$vo['url']) {
                        $data .= '"type":"click","key":"' . $vo['keyword'] . '"';
                    } else {
                        $data .= '"type":"view","url":"' . $vo['url'] . '"';
                    }
                }
                $i = 1;
                foreach ($c as $voo) {
                    $voo['url'] = str_replace(array(
                        '{siteUrl}',
                        '&amp;',
                        '&wecha_id={wechat_id}'), array(
                        $this->siteUrl,
                        '&',
                        '&diymenu=1'), $voo['url']);
                    if ($i == $count) {
                        if ($voo['url']) {
                            $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $voo['url'] .
                                '"}';
                        } else {
                            $data .= '{"type":"click","name":"' . $voo['title'] . '","key":"' . $voo['keyword'] .
                                '"}';
                        }
                    } else {
                        if ($voo['url']) {
                            $data .= '{"type":"view","name":"' . $voo['title'] . '","url":"' . $voo['url'] .
                                '"},';
                        } else {
                            $data .= '{"type":"click","name":"' . $voo['title'] . '","key":"' . $voo['keyword'] .
                                '"},';
                        }
                    }
                    $i++;
                }
                if ($c != false) {
                    $data .= ']';
                }

                if ($k == $kcount) {
                    $data .= '}';
                } else {
                    $data .= '},';
                }
                $k++;
            }
            $data .= ']}';
//            dd($data);
            file_get_contents('https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=' . $json->access_token);
            $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $json->access_token;
            $rt = $this->api_notice_increment($url, $data);

            if ($rt['rt'] == false) {
                showMessage('操作失败');
            } else {
                showMessage('操作成功');
            }
            exit;
        } else {
            showMessage('非法操作');
        }
    }

    function api_notice_increment($url, $data)
    {
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        //curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $tmpInfo = curl_exec($ch);
        $errorno = curl_errno($ch);
        if ($errorno) {
            return array('rt' => false, 'errorno' => $errorno);
        } else {
            $js = json_decode($tmpInfo, 1);
            if ($js['errcode'] == '0') {
                return array('rt' => true, 'errorno' => 0);
            } else {
                $this->error('发生错误：错误代码' . $js['errcode'] . ',微信返回错误信息：' . $js['errmsg']);
            }
        }
    }

    function curlGet($url)
    {
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        //curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $temp = curl_exec($ch);
        return $temp;
    }
}